import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";

Vue.config.productionTip = false;
import "@/common/iconfont.js";
import "@/components/vant";

import axios from "axios";
axios.defaults.baseURL = "https://d33a5037-6c63-4e92-8bb1-30018ab701ea.bspapp.com/http";
Vue.prototype.$http = axios;

Vue.mixin({
  methods: {
    checkLogin(url = "/login", msg = "请先登录", t = 1000) {
      if (!this.$store.state.uid) {
        this.$toast(msg);
        setTimeout((v) => {
          this.$router.push(url);
        }, 1000);
        return false;
      }
      return true;
    },
  },
});
let token = localStorage.getItem("token");
if (token) {
  store
    .dispatch("getUserInfo", token)
    //有token 证明登录过
    //拿token去换取数据

    // /user/getuserInfo   可能在多个地方都得被用到

    //返回用户信息 uid
    //再次存到vuex
    .then((res) => {
      new Vue({
        router,
        store,
        render: (h) => h(App),
      }).$mount("#app");
    });
} else {
  new Vue({
    router,
    store,
    render: (h) => h(App),
  }).$mount("#app");
}
